﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FaultDiagnosisSystem.Models.DataModels;

namespace FaultDiagnosisSystem.DAL
{
    public class TenMeanData
    {
        /// <summary>
        /// 指定日期和风机,获取所有的传感器数据视图集合
        /// </summary>
        /// <param name="day"></param>
        /// <param name="turbineId"></param>
        /// <returns></returns>
        internal IList<v_TenMeanData> GetViewList(DateTime day, int turbineId)
        {
            using (TurbineFaultContext context=new TurbineFaultContext())
            {
                var end = day.AddDays(1);
                
                return context.v_TenMeanData
                    .Where(d => d.TurbineId == turbineId 
                    && d.TimeStamp>=day&& d.TimeStamp<end)
                    .ToList();
            }
        }

        /// <summary>
        /// 指定风机，获取最后一天的所有的传感器数据视图集合
        /// </summary>
        /// <param name="day"></param>
        /// <param name="turbineId"></param>
        /// <returns></returns>
        internal IList<v_TenMeanData> GetViewListOfLastDay(int turbineId)
        {
            DateTime day = DateTime.Now.AddHours(-32);   //24+8=32,8小时时差
            using (TurbineFaultContext context = new TurbineFaultContext())
            {
                var end = day.AddDays(1);

                return context.v_TenMeanData
                    .Where(d => d.TurbineId == turbineId
                    && d.TimeStamp > day)
                    .ToList();
            }
        }

        /// <summary>
        /// 指定日期,获取所有的传感器数据视图集合,按时间升序排列
        /// </summary>
        /// <param name="day"></param>
        /// <param name="turbineId"></param>
        /// <returns></returns>
        internal IList<v_TenMeanData> GetViewList(DateTime day)
        {
            using (TurbineFaultContext context = new TurbineFaultContext())
            {
                var end = day.AddDays(1);

                return context.v_TenMeanData
                    .Where(d => d.TimeStamp >= day && d.TimeStamp < end)
                    .ToList();
            }
        }

        /// <summary>
        /// 指定时间,获取该时间点之后的，所有的传感器数据视图集合,按时间升序排列
        /// </summary>
        /// <param name="day"></param>
        /// <param name="turbineId"></param>
        /// <returns></returns>
        internal IList<v_TenMeanData> GetViewList2(DateTime timeStart)
        {
            using (TurbineFaultContext context = new TurbineFaultContext())
            {
                return context.v_TenMeanData
                    .Where(d => d.TimeStamp >= timeStart)
                    .ToList();
            }
        }

    }
}